/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


package br.inf.ufg.model;

import br.inf.ufg.factory.ConexaoFactoryMySql;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author umarley.faria
 */
public class CompraDAO {
    
    private final Connection con;
    private final Statement stmt;
    private final Statement stmtNavegar;
    
    
    public CompraDAO() throws ClassNotFoundException, SQLException {
            ConexaoFactoryMySql c = new ConexaoFactoryMySql();
             con = c.getConnection();
             stmt = con.createStatement();
             stmtNavegar = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
                     ResultSet.CONCUR_UPDATABLE );
    }
    
    public List<String[]> getResumoTotalVendas() throws SQLException {
        String sql = "select e.nome as \"evento\", a.descricao as \"area\", count(v.codigoingresso) as \"qtd\"" + 
                    "FROM vendas v inner join ingressos i on v.codigoingresso = i.codigo " +
                    "inner join areas a on (a.codigo = i.area and a.evento = i.evento) " +
                    "inner join eventos e on e.idevento = a.evento " +
                    "GROUP BY e.nome, a.descricao";
        ResultSet rs = stmt.executeQuery(sql);
        List<String[]> list = new ArrayList<>(0);
                
        while(rs.next()) {
            String[] row;
            row = new String[3];
            row[0] = rs.getString("evento");
            row[1] = rs.getString("area");
            row[2] = rs.getString("qtd");
            row[3] = "10";
            list.add(row);
        }
        
        return list;
    }    
}
